package com.platform.server.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.platform.server.dao.MessageDao;
import com.platform.server.response.pojo.ReturnData;
import com.platform.server.service.MessageService;
import com.szrca.ima.utils.StringTools;

@Service
@Transactional
public class MessageServiceImpl implements MessageService {
	
	@Autowired
	private MessageDao messageDao;

	/**
	 * 通知消息列表
	 */
	@Override
	public ReturnData selectMessageList(String userid,Integer pageSize, Integer pageNo) {
		if(StringTools.isEmpty(userid)){
			return new ReturnData(12,"参数有误");
		}
		PageHelper.startPage(pageNo, pageSize);	
		List<Map<String, Object>> lists = messageDao.selectMessageList(userid);
		if(lists.size() > 0){
			PageInfo<Map<String,Object>> pageInfo = new PageInfo<Map<String,Object>>(lists);
			return new ReturnData(lists,pageInfo.getPages() ,pageInfo.getTotal(),200,"成功");
		}
		return new ReturnData(100,"暂无数据");
	}

	/**
	 * 通知消息详情
	 */
	@Override
	public ReturnData selectMessageInfo(String messageid, String type) {
		if(StringTools.isEmpty(messageid) || StringTools.isEmpty(type)){
			return new ReturnData(12,"参数有误");
		}
		if("1".equals(type)){
			//查看系统通知消息详情
			Map<String, Object> message = messageDao.selectSystemMeaage(messageid, type);
			if(message != null){
				return new ReturnData(message,200,"成功");
			}
		}else if("2".equals(type)){
			//查看提现申请详情
			Map<String, Object> message = messageDao.selectWithdrawApply(messageid, type);
			if(message != null){
				return new ReturnData(message,200,"成功");
			}
		}else if("3".equals(type)){
			//查看提现到账详情
			Map<String, Object> message = messageDao.selectAccountApply(messageid, type);
			if(message != null){
				return new ReturnData(message,200,"成功");
			}
		}else if("6".equals(type)){
			//查看提现失败详情
			Map<String, Object> message = messageDao.selectlostApply(messageid, type);
			if(message != null){
				return new ReturnData(message,200,"成功");
			}
		}
		return new ReturnData(100,"未找到相关信息");
	}

}
